package com.ubs.training.web.util;

import com.ubs.training.server.dao.model.Contact;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/22/12
 * Time: 10:17 AM
 * To change this template use File | Settings | File Templates.
 */
public class ContactValidator {

    private Contact contact;
    private Errors res;

    public ContactValidator(Contact contact, Errors res) {
        this.contact = contact;
        this.res = res;

    }

    public void validate() {
        if (!StringUtils.hasLength(String.valueOf(contact.getCountryID()))) {
            res.rejectValue("country", "empty", "Should not be empty");
        }
        if (!StringUtils.hasLength(contact.getApartments())) {
            res.rejectValue("apartments", "empty", "Should not be empty");
        }
        if (!StringUtils.hasLength(contact.getCity())) {
            res.rejectValue("city", "empty", "Should not be empty");
        }
        if (!StringUtils.hasLength(contact.getDistrict())) {
            res.rejectValue("district", "empty", "Should not be empty");
        }
        if (!StringUtils.hasLength(contact.getStreet())) {
            res.rejectValue("street", "empty", "Should not be empty");
        }
    }

}
